package weiy.top.common.util;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.io.Serializable;
import java.util.List;

/**
 *
 * @Author weihc
 * @Date 2021
 */
public class PageUtils implements Serializable {

    private static final long serialVersionUID = 1L;

    private List<?> records;
    private long pages;
    private long current;
    private long size;
    private long total;

    public PageUtils(IPage<?> page) {
        this.records = page.getRecords();
        this.pages = page.getPages();
        this.current = page.getCurrent();
        this.size = page.getSize();
        this.total = page.getTotal();
    }

    /**
     * 分页
     * @param records        列表数据
     * @param total  总记录数
     * @param size    每页记录数
     * @param current    当前页数
     */
    public PageUtils(List<?> records, int total, int size, int current) {
        this.records = records;
        this.total = total;
        this.size = size;
        this.current = current;
        this.pages = (int) Math.ceil((double) total / size);
    }

    public List<?> getRecords() {
        return records;
    }

    public long getPages() {
        return pages;
    }

    public long getCurrent() {
        return current;
    }

    public long getSize() {
        return size;
    }

    public long getTotal() {
        return total;
    }

    public void setRecords(List<?> records) {
        this.records = records;
    }

    public void setPages(long pages) {
        this.pages = pages;
    }

    public void setCurrent(long current) {
        this.current = current;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public void setTotal(long total) {
        this.total = total;
    }
}
